package com.cola.custSpeechTranscription;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.digest.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @BelongsProject: custSpeechTranscription
 * @BelongsPackage: com.cola.custSpeechTranscription
 * @Author: jiangkang
 * @CreateTime: 2025-11-04  17:08
 * @Description: TODO
 * @Version: 1.0
 */
public class Test1104 {
    public static void main(String[] args) {
        ObjectMapper objectMapper = new ObjectMapper();

        Map<Object, Object> map1 = new HashMap<>();
        map1.put("role","user");
        map1.put("content","你好");

        List<Object> list = new ArrayList<>();
        list.add(map1);

        Map<Object, Object> map = new HashMap<>();
        map.put("model","V3-671B");
        map.put("uid","c015aad4f72bfcbbec85f67f52589b27");
        map.put("stream",true);
        map.put("messages",list);

        //APPID：300013079572
        //APPKEY：A0B42AD07E4532BB210448F0B5AF7220
        //ApID
        //768848
        String APPID = "300013079572";
        String APPKEY = "A0B42AD07E4532BB210448F0B5AF7220";
        String ApID = "768848";

        String platformCode = "PLATFORM1031";
        String timestamp = timestamp();
        String traId = getTraId();

        System.out.println("时间为："+timestamp);
        System.out.println("traceid为："+traId);

        Map<Object, Object> body = new HashMap<>();
        body.put("originalData",map);
        try{
            String jsonString1 = objectMapper.writeValueAsString(map);

            String str = String.join("",
                    // 优先取上一节点，其次取全局变量，最后取应用配置
                    APPID,APPKEY,traId,timestamp,jsonString1);
            System.out.println("拼接为："+str);
            String sign = DigestUtils.md5Hex(str);

            body.put("sign",sign);
            String jsonString = objectMapper.writeValueAsString(body);
            System.out.println(jsonString);
        }catch (Exception e){

        }
    }

    public static String getTraId() {
        // 生成随机的 UUID
        UUID uuid = UUID.randomUUID();
        String randomUUIDString = uuid.toString();
        String uuidWithoutHyphens = randomUUIDString.replaceAll("-", "");
        return uuidWithoutHyphens;
    }


    public static String timestamp() {
        Date now = new Date();
        // 定义时间格式
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        // 格式化当前时间
        String timestamp = formatter.format(now);
        return timestamp;
    }
}